﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class AsistenteDirector_altaMaestros : System.Web.UI.Page
{
    modeloProfesores mprof = new modeloProfesores();
    claseprofesor oProf = new claseprofesor();

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        GridView1.DataSource = mprof.buscarProfesor(TextBox1.Text.Trim());
        GridView1.DataBind();
        try
        {
            lblControl.Text = GridView1.Rows[0].Cells[1].Text;
            lblProfesor.Text = GridView1.Rows[0].Cells[2].Text;
            txtUser.Text = GridView1.Rows[0].Cells[4].Text;
        }
        catch (Exception ex) {
            Response.Write("<script>alert('" + ex.Message + "');</script>");
        }
    }
    protected void btnBuscar_Click(object sender, EventArgs e)
    {
        
    }

    protected void btnGuardar_Click(object sender, EventArgs e)
    {
        oProf.Id_prof = Convert.ToInt32(lblControl.Text);
        oProf.Profesor = lblProfesor.Text;
        oProf.Usuario = txtUser.Text;
        oProf.Contraseña = txtContraseña.Text;
        mprof.actualizarDatos(oProf);
        this.borrarTodo();
    }

    private void borrarTodo() {
        lblControl.Text = "";
        lblProfesor.Text = "";
        txtUser.Text = "";
        TextBox1.Text = "";
        GridView1.DataSource = null;
        GridView1.DataBind();
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblControl.Text = GridView1.Rows[GridView1.SelectedRow.RowIndex].Cells[1].Text;
        lblProfesor.Text = GridView1.Rows[GridView1.SelectedRow.RowIndex].Cells[2].Text;
        txtUser.Text = GridView1.Rows[GridView1.SelectedRow.RowIndex].Cells[4].Text;
    }
}